package com.turnengine.client.local.upkeep.command;

import com.turnengine.client.local.upkeep.enums.UpkeepConditionType;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Add Upkeep Condition.
 */
public class AddUpkeepCondition implements IAddUpkeepCondition {

	/** The command id. */
	public static final short COMMAND_ID = 2102;

	/** The login id. */
	private long loginId;
	/** The instance id. */
	private int instanceId;
	/** The upkeep id. */
	private int upkeepId;
	/** The type. */
	private UpkeepConditionType type;
	/** The condition id. */
	private int conditionId;
	/** The condition amount. */
	private long conditionAmount;

	/**
	 * Creates a new Add Upkeep Condition.
	 */
	public AddUpkeepCondition() {
	}

	/**
	 * Creates a new Add Upkeep Condition.
	 * @param loginId the login id
	 * @param instanceId the instance id
	 * @param upkeepId the upkeep id
	 * @param type the type
	 * @param conditionId the condition id
	 * @param conditionAmount the condition amount
	 */
	public AddUpkeepCondition(long loginId, int instanceId, int upkeepId, UpkeepConditionType type, int conditionId, long conditionAmount) {
		setLoginId(loginId);
		setInstanceId(instanceId);
		setUpkeepId(upkeepId);
		setType(type);
		setConditionId(conditionId);
		setConditionAmount(conditionAmount);
	}

	/**
	 * Creates a new Add Upkeep Condition.
	 * @param iAddUpkeepCondition the i add upkeep condition
	 */
	public AddUpkeepCondition(IAddUpkeepCondition iAddUpkeepCondition) {
		setLoginId(iAddUpkeepCondition.getLoginId());
		setInstanceId(iAddUpkeepCondition.getInstanceId());
		setUpkeepId(iAddUpkeepCondition.getUpkeepId());
		setType(iAddUpkeepCondition.getType());
		setConditionId(iAddUpkeepCondition.getConditionId());
		setConditionAmount(iAddUpkeepCondition.getConditionAmount());
	}

	/**
	 * Returns the login id.
	 * @return the login id.
	 */
	public long getLoginId() {
		return loginId;
	}

	/**
	 * Returns the instance id.
	 * @return the instance id.
	 */
	public int getInstanceId() {
		return instanceId;
	}

	/**
	 * Returns the upkeep id.
	 * @return the upkeep id.
	 */
	public int getUpkeepId() {
		return upkeepId;
	}

	/**
	 * Returns the type.
	 * @return the type.
	 */
	public UpkeepConditionType getType() {
		return type;
	}

	/**
	 * Returns the condition id.
	 * @return the condition id.
	 */
	public int getConditionId() {
		return conditionId;
	}

	/**
	 * Returns the condition amount.
	 * @return the condition amount.
	 */
	public long getConditionAmount() {
		return conditionAmount;
	}

	/**
	 * Sets the login id.
	 * @param loginId the login id to set.
	 */
	public void setLoginId(long loginId) {
		this.loginId = loginId;
	}

	/**
	 * Sets the instance id.
	 * @param instanceId the instance id to set.
	 */
	public void setInstanceId(int instanceId) {
		this.instanceId = instanceId;
	}

	/**
	 * Sets the upkeep id.
	 * @param upkeepId the upkeep id to set.
	 */
	public void setUpkeepId(int upkeepId) {
		this.upkeepId = upkeepId;
	}

	/**
	 * Sets the type.
	 * @param type the type to set.
	 */
	public void setType(UpkeepConditionType type) {
		if (type == null) {
			throw new NullPointerException("type");
		}
		this.type = type;
	}

	/**
	 * Sets the condition id.
	 * @param conditionId the condition id to set.
	 */
	public void setConditionId(int conditionId) {
		this.conditionId = conditionId;
	}

	/**
	 * Sets the condition amount.
	 * @param conditionAmount the condition amount to set.
	 */
	public void setConditionAmount(long conditionAmount) {
		this.conditionAmount = conditionAmount;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(1289, 37);
		hash.append(loginId);
		hash.append(instanceId);
		hash.append(upkeepId);
		hash.append(type);
		hash.append(conditionId);
		hash.append(conditionAmount);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof AddUpkeepCondition) {
			AddUpkeepCondition compare = (AddUpkeepCondition) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.loginId, compare.loginId);
			equals.append(this.instanceId, compare.instanceId);
			equals.append(this.upkeepId, compare.upkeepId);
			equals.append(this.type, compare.type);
			equals.append(this.conditionId, compare.conditionId);
			equals.append(this.conditionAmount, compare.conditionAmount);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IAddUpkeepCondition compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.loginId, compare.getLoginId());
		builder.append(this.instanceId, compare.getInstanceId());
		builder.append(this.upkeepId, compare.getUpkeepId());
		builder.append(this.type, compare.getType());
		builder.append(this.conditionId, compare.getConditionId());
		builder.append(this.conditionAmount, compare.getConditionAmount());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("loginId", loginId);
		string.append("instanceId", instanceId);
		string.append("upkeepId", upkeepId);
		if (type != null) {
			string.append("type", type);
		}
		string.append("conditionId", conditionId);
		string.append("conditionAmount", conditionAmount);
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
